Hi Steve,
Not sure why it is taking Yahoo so long to post the attachment. Here it is pasted below.
Regards
TK
#include "KMotionDef.h"
// function prototypes for compiler
int Debounce(int n, int *cnt, int *last, int *lastsolid);
// state variables for switch debouncing
int mlast=0,mlastsolid=-1,mcount=0;
main()
{
for (;;) // loop forever
{
WaitNextTimeSlice();
// Debounce Momentary Push Button
if (Debounce(ReadBit(1038),&mcount,&mlast,&mlastsolid) == 1)
{
if (ReadBit(149))
{
ClearBit(149);
ClearBit(50);
}
else
{
SetBit(149);
SetBit(50);
}
}
}
}
// Debounce a bit
//
// return 1 one time when first debounced high
// return 0 one time when first debounced low
// return -1 otherwise
#define DBTIME 300
int Debounce(int n, int *cnt, int *last, int *lastsolid)
{
int v = -1;
if (n == *last) // same as last time?
{
if (*cnt == DBTIME-1)
{
if (n != *lastsolid)
{
v =
*lastsolid = n; // return debounced value
}
}
if (*cnt < DBTIME) (*cnt)++;
}
else
{
*cnt = 0; // reset count
}
*last = n;
return v;
}